package h1.sismetro.gui;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Dimension;
import h1.sismetro.classesbasicas.Ferramenta;
import h1.sismetro.negocio.almoxarifado.CadastroFerramenta;
public class TelaFerramenta extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTextField jTextFieldNomeFerramenta = null;
	private JLabel jLabelNome = null;
	private JLabel jLabelCodigo = null;
	private JTextField jTextFieldCodigoFerramenta = null;
	private JLabel jLabelQTD = null;
	private JTextField jTextFieldQTD = null;
	private JButton jButtonCadastrar = null;
	private JButton jButtonPesquisar = null;
	private JButton jButtonAlterar = null;
	private JLabel jLabelTitulo = null;
    private Ferramenta minhaFerramenta = new Ferramenta();  //  @jve:decl-index=0:
	private CadastroFerramenta cadastroFerr = new CadastroFerramenta();  //  @jve:decl-index=0:
	private JButton jButtonConfirmaCadastro = null;
    /**
	 * This is the default constructor
	 */
	public TelaFerramenta() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabelTitulo = new JLabel();
		jLabelTitulo.setBounds(new Rectangle(202, 3, 93, 16));
		jLabelTitulo.setText("FERRAMENTAS");
		jLabelQTD = new JLabel();
		jLabelQTD.setBounds(new Rectangle(2, 121, 70, 16));
		jLabelQTD.setText("Quantidade");
		jLabelCodigo = new JLabel();
		jLabelCodigo.setBounds(new Rectangle(0, 30, 45, 16));
		jLabelCodigo.setText("Codigo");
		jLabelNome = new JLabel();
		jLabelNome.setBounds(new Rectangle(0, 76, 122, 16));
		jLabelNome.setText("Nome da Ferramenta");
		this.setSize(500, 180);
		this.setLayout(null);
		this.add(getJTextFieldNomeFerramenta(), null);
		this.add(jLabelNome, null);
		this.add(jLabelCodigo, null);
		this.add(getJTextFieldCodigoFerramenta(), null);
		this.add(jLabelQTD, null);
		this.add(getJTextFieldQTD(), null);
		this.add(getJButtonCadastrar(), null);
		this.add(getJButtonPesquisar(), null);
		this.add(getJButtonAlterar(), null);
		this.add(jLabelTitulo, null);
		this.add(getJButtonConfirmaCadastro(), null);
	}

	/**
	 * This method initializes jTextFieldNomeFerramenta	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldNomeFerramenta() {
		if (jTextFieldNomeFerramenta == null) {
			jTextFieldNomeFerramenta = new JTextField();
			jTextFieldNomeFerramenta.setBounds(new Rectangle(137, 76, 198, 16));
		}
		return jTextFieldNomeFerramenta;
	}

	/**
	 * This method initializes jTextFieldCodigoFerramenta	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCodigoFerramenta() {
		if (jTextFieldCodigoFerramenta == null) {
			jTextFieldCodigoFerramenta = new JTextField();
			jTextFieldCodigoFerramenta.setBounds(new Rectangle(137, 30, 66, 17));
		}
		return jTextFieldCodigoFerramenta;
	}

	/**
	 * This method initializes jTextFieldQTD	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldQTD() {
		if (jTextFieldQTD == null) {
			jTextFieldQTD = new JTextField();
			jTextFieldQTD.setBounds(new Rectangle(138, 123, 73, 16));
		}
		return jTextFieldQTD;
	}

	/**
	 * This method initializes jButtonCadastrar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCadastrar() {
		if (jButtonCadastrar == null) {
			jButtonCadastrar = new JButton();
			jButtonCadastrar.setBounds(new Rectangle(386, 40, 97, 19));
			jButtonCadastrar.setText("Cadastrar");
			jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try{
					jTextFieldCodigoFerramenta.setText(String.valueOf(cadastroFerr.obterCodigo()));
					}
					catch (Exception ex1) {
						// TODO: handle exception
					}
				}
			});
		}
		return jButtonCadastrar;
	}

	/**
	 * This method initializes jButtonPesquisar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonPesquisar() {
		if (jButtonPesquisar == null) {
			jButtonPesquisar = new JButton();
			jButtonPesquisar.setBounds(new Rectangle(386, 78, 101, 17));
			jButtonPesquisar.setText("Pesquisar");
		}
		return jButtonPesquisar;
	}

	/**
	 * This method initializes jButtonAlterar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAlterar() {
		if (jButtonAlterar == null) {
			jButtonAlterar = new JButton();
			jButtonAlterar.setBounds(new Rectangle(399, 110, 77, 18));
			jButtonAlterar.setText("Alterar");
		}
		return jButtonAlterar;
	}

	/**
	 * This method initializes jButtonConfirmaCadastro	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonConfirmaCadastro() {
		if (jButtonConfirmaCadastro == null) {
			jButtonConfirmaCadastro = new JButton();
			jButtonConfirmaCadastro.setBounds(new Rectangle(344, 140, 152, 19));
			jButtonConfirmaCadastro.setText("Confirmar Cadastro");
			jButtonConfirmaCadastro.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				    try{
					int x = Integer.getInteger(jTextFieldCodigoFerramenta.getText());
					minhaFerramenta.setCodigo(x);
					minhaFerramenta.setNome(jTextFieldNomeFerramenta.getText());
					minhaFerramenta.setQtd(Integer.getInteger(jTextFieldQTD.getText()));
					cadastroFerr.cadastrar(minhaFerramenta);
				    }
				    catch (Exception ex) {
						// TODO: handle exception
					}
					
				}
			});
		}
		return jButtonConfirmaCadastro;
	}

}  //  @jve:decl-index=0:visual-constraint="12,8"
